package com.ruoyi.web.controller.translation;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.translat.domain.ShortPlayCopyright;
import com.ruoyi.translat.domain.ShortPlayCopyrightVO;
import com.ruoyi.translat.service.IShortPlayCopyrightService;
import com.ruoyi.web.controller.until.CheckUtilsAdm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 短剧版权链接Controller
 *
 * @author ruoyi
 * @date 2025-10-26
 */
@RestController
@RequestMapping("/short/play/copyrigh/")
public class ShortPlayCopyrightController extends BaseController {
    @Autowired
    private IShortPlayCopyrightService shortPlayCopyrightService;

    /**
     * 查询短剧版权链接列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ShortPlayCopyright shortPlayCopyright) {
        startPage();
        List<ShortPlayCopyright> list = shortPlayCopyrightService.selectShortPlayCopyrightList(shortPlayCopyright);
        return getDataTable(list);
    }

    @GetMapping("/listTwo")
    public AjaxResult listTwo(ShortPlayCopyright shortPlayCopyright) {
        List<ShortPlayCopyright> list = shortPlayCopyrightService.selectShortPlayCopyrightList(shortPlayCopyright);
        if (list != null && list.size() > 0) {
            List<ShortPlayCopyrightVO> shortPlayCopyrightVOS = CheckUtilsAdm.entityListToModelList(list, ShortPlayCopyrightVO.class);
            return success(shortPlayCopyrightVOS);
        }
        return AjaxResult.success("暂无数据");
    }


    /**
     * 导出短剧版权链接列表
     */
    @Log(title = "短剧版权链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShortPlayCopyright shortPlayCopyright) {
        List<ShortPlayCopyright> list = shortPlayCopyrightService.selectShortPlayCopyrightList(shortPlayCopyright);
        ExcelUtil<ShortPlayCopyright> util = new ExcelUtil<ShortPlayCopyright>(ShortPlayCopyright.class);
        util.exportExcel(response, list, "短剧版权链接数据");
    }

    /**
     * 获取短剧版权链接详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(shortPlayCopyrightService.selectShortPlayCopyrightById(id));
    }

    /**
     * 新增短剧版权链接
     */
    @Log(title = "短剧版权链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShortPlayCopyright shortPlayCopyright) {
        return toAjax(shortPlayCopyrightService.insertShortPlayCopyright(shortPlayCopyright));
    }

    /**
     * 修改短剧版权链接
     */
    @Log(title = "短剧版权链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShortPlayCopyright shortPlayCopyright) {
        return toAjax(shortPlayCopyrightService.updateShortPlayCopyright(shortPlayCopyright));
    }

    /**
     * 删除短剧版权链接
     */
    @Log(title = "短剧版权链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shortPlayCopyrightService.deleteShortPlayCopyrightByIds(ids));
    }
}
